<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ProducerDAO
 *
 * @author Hoang Thanh Duc
 */
class ProducerDAO {

    function getProducer($id){
        $producer = new Producer();
        $row = $producer->fetchRow("id = $id and status =".Constant::$STATUS_AVAILABLE);
        return $row;
    }

    function getProducerList(){
       $producer = new Producer();
       $row = $producer->fetchAll($producer->select()->where('status = ?',Constant::$STATUS_AVAILABLE));
       return $row;
    }

    function searchProducer($name){
        $producer = new Producer();
        $row = $producer->fetchAll("status =".Constant::$STATUS_AVAILABLE." and name LIKE '%$name%'");
        return $row;
    }

    function addProducer($data){
        $producer = new Producer();

        $producer->insert($data);
    }

    function editProducer($array){
    	$producer = new Producer();
        $where = $producer->getAdapter()->quoteInto('id = ?', $array['id']);
        $producer->update($array,$where);
    }

    function deleteProducer($id){
        $producer = new Producer();
        $data = array('status'=>Constant::$STATUS_DELETED);
        $where = $producer->getAdapter()->quoteInto('id = ?', $id);
        $producer->update($data, $where);
    }
}
?>